import numpy as np
import pandas as pd

# r=np.random.rand(2,3)
# r=np.random.randn(2,3)
# r=np.random.randint(2,15,(2,3))
# print(r)
# df=pd.DataFrame(np.random.randint(1,10,(10,5)),columns=(list('ABCDE')))
# df = pd.DataFrame({'A': ['foo', 'bar', 'foo', 'bar',
#                          'foo', 'bar', 'foo', 'foo'],
#                    'B': ['one', 'one', 'two', 'three',
#                          'two', 'two', 'one', 'three'],
#                    'C': np.random.randn(8),
#                    'D': np.random.randn(8)})
# df=df.groupby(['A','B']).sum()
# print(df)
# print(df.to_dict())
# print(df.columns)
# print(df[['C','D']])
# print(df.loc[('bar','two'):('foo','three'),['C']])
# print(df.at[('bar','one'),'C'])

# tuples = list(zip(*[['bar', 'bar', 'baz', 'baz',
#                      'foo', 'foo', 'qux', 'qux'],
#                     ['one', 'two', 'one', 'two',
#                      'one', 'two', 'one', 'two']]))
# index = pd.MultiIndex.from_tuples(tuples, names=['first', 'second'])
# df = pd.DataFrame(np.random.randn(8, 2), index=index, columns=['A', 'B'])
# # print(df)
# df2 = df[:4]
# # print(df2)
# stacked = df2.stack()
# stacked =stacked.unstack(0).unstack(1)
# print(stacked)


# df = pd.DataFrame({'A': ['one', 'one', 'two', 'three'] * 3,
#                    'B': ['A', 'B', 'C'] * 4,
#                    'C': ['foo', 'foo', 'foo', 'bar', 'bar', 'bar'] * 2,
#                    'D': np.random.randn(12),
#                    'E': np.random.randn(12)})
# print(df)
# df=pd.pivot_table(df, index=['A'],aggfunc= [len,np.count_nonzero])
# df1=pd.pivot_table(df, index=['A'],aggfunc=np.sum)
# print(df1)
# print(df.index)
# print(df.columns)
# df2=pd.pivot_table(df, index=['A'],aggfunc=np.mean)
# print(df2)

# d1 = [{'name':'alice', 'score':38}, {'name':'bob', 'score':18}, {'name':'darl', 'score':28}, {'name':'christ', 'score':28}]
# l = sorted(d1, key=lambda x:(x['score'], x['name']))
# print(l)

# roles = ["OWNER", "RCOM", "HRGDL2", "HRM", "HRH", "MP", "HP", "VP", "GM"]
# info = {"VP": "80003", "HRM": "F140019", "MP": "F130008", "HRGDL2": "F140390", "OWNER": "F133255", "RCOM": "F900151", "GM": "00903", "HP": "80355", "HRH": "81453"}
# sorted_dict = map(lambda x:{x:info[x]}, roles)
# print(list(sorted_dict))

# dic={'郑州市':30,'b':15,'c':9}
# l=['a','b','c']
# ll=sorted(l,key=lambda x:dic[x])
# print(ll)